//
//  NYSquareButton.m
//  BS
//
//  Created by neal on 15/8/19.
//  Copyright (c) 2015年 Neal. All rights reserved.
//

#import "NYSquareButton.h"
#import "NYSquareModel.h"
#import <UIButton+WebCache.h>

@implementation NYSquareButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"mainCellBackground"] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
     self.imageView.y = self.height * 0.1;
    self.imageView.height = self.height * 0.5;
    self.imageView.width = self.height * 0.5;
    self.imageView.centerX = self.width * 0.5;
    
    self.titleLabel.y = CGRectGetMaxY(self.imageView.frame);
    self.titleLabel.x = 0 ;
    self.titleLabel.width = self.width;
    self.titleLabel.height = self.height - self.titleLabel.y;
    
}
- (void)setSquare:(NYSquareModel *)square
{
    _square = square;
    [self setTitle:square.name forState:UIControlStateNormal];
    [self sd_setImageWithURL:[NSURL URLWithString:square.icon] forState:UIControlStateNormal];

}

@end
